package com.u3k.mid;

import com.u3k.app.mid.RegisterManager;
import com.u3k.app.mid.core.ModuleManager;
import com.u3k.app.mid.utils.common.Util;
import com.u3k.app.mid.utils.net.Callback;
import com.u3k.app.mid.utils.net.Response;
import com.u3k.app.mid.utils.statistics.StatisticsManager;
import org.json.JSONObject;

class n implements Callback {
    final /* synthetic */ m a;

    n(m mVar) {
        this.a = mVar;
    }

    public void onFailure(int i, String str) {
        this.a.c.mRegistering = false;
        ay.b(this.a.c.mContext);
        LogUtils.LogError(RegisterManager.TAG, "register  onFailure code=" + i + ", errMsg=" + str);
        if (this.a.b != null) {
            this.a.b.onFailed();
        }
    }

    public void onResponse(Response response) {
        this.a.c.mRegistering = false;
        String string = response.getString();
        LogUtils.LogError(RegisterManager.TAG, "register   onResponse  resp=" + string);
        try {
            JSONObject jSONObject = new JSONObject(string);
            try {
                ay.a(this.a.c.mContext);
                if (jSONObject.has("domain")) {
                    ay.a(this.a.a, jSONObject.optString("domain"));
                }
            } catch (Exception e) {
                StatisticsManager.getInstance().logException(ae.a(), e);
            }
            string = jSONObject.getString("result");
            if (string != null && !string.equals("0")) {
                if (jSONObject.has("token")) {
                    Util.saveUserToken(this.a.a, jSONObject.getString("token"));
                }
                if (jSONObject.has("srvImei")) {
                    Util.saveServImei(this.a.a, jSONObject.getString("srvImei"));
                }
                if (jSONObject.has("modules")) {
                    LogUtils.LogError(RegisterManager.TAG, "register   onResponse  MODULES!=null");
                    ModuleManager.getInstance(this.a.c.mContext).parseModuleInfos(jSONObject.getJSONArray("modules"));
                }
                if (this.a.b != null) {
                    LogUtils.LogError(RegisterManager.TAG, "register   onResponse  listener!=null");
                    this.a.b.onSuccess();
                }
            } else if (this.a.b != null) {
                this.a.b.onFailed();
            }
        } catch (Exception e2) {
            LogUtils.LogError(RegisterManager.TAG, "register   onResponse  JSONException=", e2);
            if (this.a.b != null) {
                this.a.b.onFailed();
            }
            StatisticsManager.getInstance().logException(ae.a(), e2);
        }
    }
}
